import {reqPayInfo, reqPayResult} from '@/api/index.js';
import {value} from "lodash/seq";

// 材料：
let state = {
    payInfo: {},
    code: "",
};

// 加工：
let getters = {

};

// 厨师：
let mutations = {
    SET_PAY_INFO(state, value) {
        state.payInfo = value;
    },
    SET_CODE(state, value) {
        state.code = value;
    }
};

// 迎宾：
let actions = {
    // 获取支付信息
    async reqPayInfo({commit, state, dispatch}, orderId) {
        let result = await reqPayInfo(orderId);
        console.log(result);
        if (result.code === 200) {
            commit('SET_PAY_INFO', result.data);
            return result;
        } else {
            return Promise.reject(new Error(result.message));
        }
    },
    // 查询支付结果
    async reqPayResult({commit, state, dispatch}, orderId) {
        let result = await reqPayResult(orderId);
        console.log(result);
        if (result.code === 200 || result.code === 205) {
            commit('SET_CODE', result.code);
            return result;
        } else {
            return Promise.reject(new Error(result.message));
        }
    },
};

// 对外暴露
export default {
    state,
    mutations,
    actions,
    getters
};
